package com.example.wechat.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wechat.R;
import com.example.wechat.adapter.StickerAdapter;
import com.example.wechat.model.Sticker;

import java.util.ArrayList;
import java.util.List;

public class StickerAlbumActivity extends AppCompatActivity implements StickerAdapter.OnStickerClickListener {
    private RecyclerView recyclerView;
    private StickerAdapter stickerAdapter;
    private List<Sticker> stickers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sticker_album);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("表情卡包相册");

        recyclerView = findViewById(R.id.sticker_recycler_view);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));

        stickers = new ArrayList<>();
        stickerAdapter = new StickerAdapter(stickers, this);
        recyclerView.setAdapter(stickerAdapter);

        loadStickers();
    }

    private void loadStickers() {
        // TODO: 从数据库或服务器加载表情包
        // 这里添加一些测试数据
        stickers.add(new Sticker("笑脸", R.drawable.ic_sticker));
        stickers.add(new Sticker("哭脸", R.drawable.ic_sticker));
        stickers.add(new Sticker("生气", R.drawable.ic_sticker));
        stickers.add(new Sticker("惊讶", R.drawable.ic_sticker));
        stickerAdapter.notifyDataSetChanged();
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onStickerClick(Sticker sticker) {
        Toast.makeText(this, "点击了表情：" + sticker.getName(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFavoriteClick(Sticker sticker) {
        sticker.setFavorite(!sticker.isFavorite());
        stickerAdapter.notifyDataSetChanged();
        Toast.makeText(this, sticker.isFavorite() ? "已收藏" : "已取消收藏", Toast.LENGTH_SHORT).show();
    }
} 